script_enemy_main{

let nr=GetArgument;
let size=0;

let angle=0;
let radius=0;
let accel=0;
let speed=0;

let usespell=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshotb5=("\script\SoundEffects\shotb5.wav");
let SEshotm8=("\script\SoundEffects\shotm8.wav");

let GRfamiliar=("\script\Images\OtherEffects\SpellCircle1b.png");

@Initialize{
	LoadSE("\script\SoundEffects\shotb5.wav");
	LoadSE("\script\SoundEffects\shotm8.wav");
	
	LoadGraphic("\script\Images\OtherEffects\SpellCircle1b.png");

	SetScore(1);
	SetLife(1);
}
	
@MainLoop{

let phase=GetCommonData("SpellcardPhase");
let movetime=60;

if(time==0){
let xpos=GetPlayerX;
let ypos=GetPlayerY;
if(nr==0){ xpos=minx-2; ypos=cy; SetAngle(270); }
if(nr==1){ xpos=maxx+2; ypos=cy; SetAngle(90); }
if(nr==2){ xpos=cx; ypos=miny-2; SetAngle(0); }
if(nr==3){ xpos=cx; ypos=maxy+2; SetAngle(180); }
if(nr==4){ xpos=minx; ypos=miny; }
if(nr==5){ xpos=maxx; ypos=miny; }
if(nr==6){ xpos=minx; ypos=maxy; }
if(nr==7){ xpos=maxx; ypos=maxy; }
	angle=atan2(ypos-GetY,xpos-GetX);
	radius=(((xpos-GetX)^2+(ypos-GetY)^2)^0.5)/movetime*(pi/2);
}
if(time<movetime){
	accel+=180/movetime;
	speed=radius*sin(accel);
	SetX(GetX+speed*cos(angle));
	SetY(GetY+speed*sin(angle));
}

if(time>=movetime && nr<4){
	if(GetX<=minx && GetY<=miny){ SetAngle(0); }
	if(GetX>=maxx && GetY<=miny){ SetAngle(90); }
	if(GetX>=maxx && GetY>=maxy){ SetAngle(180); }
	if(GetX<=minx && GetY>=maxy){ SetAngle(270); }
SetSpeed(1.5);
}


if(time%140==0 && nr<4 && time>=90){
SetShotDirectionType(PLAYER);
let speed=0.8;
let color=1;
	loop(10){
		if(phase<3){
			CreateShot01(GetX,GetY,speed,0,12+color,10);
		}
		if(phase>=3){
		let angle=-45;
			loop(3){
			CreateShot01(GetX,GetY,speed,angle,12+color,10);
			angle+=45;
			}
		}
	speed+=0.2;
	color+=1;
	}
SetShotDirectionType(ABSOLUTE);
PlaySE(SEshotm8);
}

if((time+200)%280==0 && nr>=4 && time>=70){
	SetShotDirectionType(PLAYER);
	if(phase<5){
	CreateShot01(GetX,GetY,1,0,59,10);
	}
	if(phase>=5){
	let angle=-45;
		loop(3){
		CreateShot01(GetX,GetY,1,angle,59,10);
		angle+=45;
		}
	}
	SetShotDirectionType(ABSOLUTE);
PlaySE(SEshotb5);
}

if(size<1){ size+=0.01; }


time++;
frame++;
}

@DrawLoop{
	SetGraphicScale(0.25,0.25);
	SetTexture(GRfamiliar);
	SetGraphicAngle(0,0,time*2);
	if(nr<4){ SetColor(255,128,128); }
	if(nr>=4){ SetColor(128,128,255); }
	SetRenderState(ADD);
	SetAlpha(255);
	SetGraphicRect(0,0,200,200);
	DrawGraphic(GetX,GetY);
}

@Finalize{
}

}